package com.kuhyygy.activity;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.xmlpull.v1.XmlPullParser;

import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;
import android.widget.SimpleAdapter;

import com.kuhyygy.R;
import com.kuhyygy.bean.CommonUI;
import com.kuhyygy.uitl.MemoryLoader;

public class CommonUIActivity extends BaseActivity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.common_ui_list);
		ListView lv = (ListView) findViewById(R.id.commonUIList);
		XmlPullParser parser = getResources().getXml(R.xml.commonui);
		List<CommonUI> menus = MemoryLoader.getInstance().loadCommonUI(parser);
		String[] from = { "name", "toPage" };
		int[] to = { R.id.commonUiName, R.id.commonUiToPage };
		List<Map<String, ?>> list = new ArrayList<Map<String, ?>>();
		for (CommonUI c : menus) {
			Map<String, String> m = new HashMap<String, String>();
			m.put("name", c.getName());
			m.put("toPage", c.getToPage());
			list.add(m);
		}
		SimpleAdapter adapter = new SimpleAdapter(this, list,
				R.layout.commonui_item, from, to);
		lv.setAdapter(adapter);
		lv.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> adView, View view, int arg2,
					long arg3) {
				System.out.println(adView.getId()+ ":" + adView.toString() + "=====" + view.getId()+":" + view.toString());
			}
		});
	}
	
}
